package com.cheng.example.geektime.designpatterns.j60.v4;

import java.util.HashMap;
import java.util.Map;

// 策略的创建
public class DiscountStrategyFactory {
    private static final Map<OrderType, DiscountStrategy> strategies = new HashMap<>();

    static {
        strategies.put(OrderType.NORMAL, new NormalDiscountStrategy());
        strategies.put(OrderType.GROUPON, new GrouponDiscountStrategy());
        strategies.put(OrderType.PROMOTION, new PromotionDiscountStrategy());
    }

    public static DiscountStrategy getDiscountStrategy(OrderType type) {
        return strategies.get(type);
    }
}

//public class DiscountStrategyFactory {
//    public static DiscountStrategy getDiscountStrategy(OrderType type) {
//        if (type == null) {
//            throw new IllegalArgumentException("Type should not be null.");
//        }
//        if (type.equals(OrderType.NORMAL)) {
//            return new NormalDiscountStrategy();
//        } else if (type.equals(OrderType.GROUPON)) {
//            return new GrouponDiscountStrategy();
//        } else if (type.equals(OrderType.PROMOTION)) {
//            return new PromotionDiscountStrategy();
//        }
//        return null;
//    }
//}